
//quan ly cac frame anh duoc xep theo chieu doc
public class FrameImage
{
	public int frameWidth;
	public int frameHeight;
	public int nFrame;
	
	private Image imgFrame;
	private int[] pos;
	private int totalHeight;
	
	public FrameImage(Image img,int width,int height)
	{
		
		imgFrame=img;
		frameWidth=width;
		frameHeight=height;
		totalHeight=img.getHeight();
		nFrame=totalHeight/height;
		pos=new int[nFrame];
		for (int i=0;i<nFrame;i++)
			pos[i]=i*height;
	}
	
	

	public void drawFrame(int idx,int x,int y,int trans,mGraphics g)
	{
		if (idx>=0 && idx<nFrame)
			g.drawRegion(imgFrame,0,pos[idx],frameWidth,frameHeight,trans,x,y,0);
//		g.drawRegion(imgFrame,0,pos[idx],frameWidth,frameHeight,trans,x,CCanvas.height-18,Graphics.BOTTOM|Graphics.HCENTER);
		
	}

	public void map(int idx,int x,int y,int trans,mGraphics g)
	{
		if (idx>=0 && idx<nFrame)
//			g.drawRegion(imgFrame,0,pos[idx],frameWidth,frameHeight,trans,x,y,0);
		g.drawRegion(imgFrame,0,pos[idx],frameWidth,frameHeight,trans,x,y,mGraphics.BOTTOM|mGraphics.HCENTER);
		
	}
	
	public void drawFrame_linh(int idx,int x,int y,int trans,mGraphics g)
	{
		if (idx>=0 && idx<nFrame)
//			g.drawRegion(imgFrame,0,pos[idx],frameWidth,frameHeight,trans,x,y,0);
		g.drawRegion(imgFrame,0,pos[idx],frameWidth,frameHeight,trans,x,y,mGraphics.BOTTOM|mGraphics.HCENTER);
		
	}
	
	public void drawText(int idx,int x,int y,int trans,mGraphics g)
	{
		if (idx>=0 && idx<nFrame)
            g.drawRegion(imgFrame, 0, pos[idx], frameWidth, frameHeight, trans, x, y, mGraphics.HCENTER | mGraphics.VCENTER);
	}

    public void drawCharFrame(int idx, int x, int y, int trans, mGraphics g)
	{
		x=x+16;
		if (idx>=0 && idx<nFrame)
            g.drawRegion(imgFrame, 0, pos[idx], frameWidth, frameHeight, trans, x, y, mGraphics.BOTTOM | mGraphics.HCENTER);
	}
		
	public void unload()
	{
		imgFrame=null;
		pos=null;
	}
}